
#include "sc8701_bus.h"


static void init(void *handle, uint16_t duty_max)
{
    sc8701_bus_handle_t *t = (sc8701_bus_handle_t *)handle;
    pwm_out_bus.init(&t->pwm_u, duty_max, 24000);
    pwm_out_bus.init(&t->pwm_i, duty_max, 24000);
}

static void enable(void *handle, uint8_t enable)
{
    sc8701_bus_handle_t *t = (sc8701_bus_handle_t *)handle;
    hal_pin_write(&t->cs, enable==0);
}

static void set_u_duty(void *handle, uint16_t duty)
{
    sc8701_bus_handle_t *t = (sc8701_bus_handle_t *)handle;
    pwm_out_bus.adjust(&t->pwm_u, duty);
}

static void set_i_duty(void *handle, uint16_t duty)
{
    sc8701_bus_handle_t *t = (sc8701_bus_handle_t *)handle;
    pwm_out_bus.adjust(&t->pwm_i, duty);
}
    
sc8701_bus_t sc8701_bus = 
{
    .init = init,
    .enable = enable,
    .set_i_duty = set_i_duty,
    .set_u_duty = set_u_duty,
};
